#!/bin/sh
# - ip

cat > /etc/sysconfig/network-scripts/ifcfg-enp189s0f3 << EOF
TYPE=Ethernet
PROXY_METHOD=none
BROWSER_ONLY=no
BOOTPROTO=none
DEFROUTE=yes
IPV4_FAILURE_FATAL=no
IPV6INIT=yes
IPV6_AUTOCONF=yes
IPV6_DEFROUTE=yes
IPV6_FAILURE_FATAL=no
IPV6_ADDR_GEM_MODE=eui64
NAME=enp189s0f3
DEVICE=enp189s0f3
ONBOOT=yes
IPADDR=192.168.222.1
NETMASK=255.255.255.0
GATEWAY=192.168.222.1
EOF
sudo ifdown enp189s0f3
sudo ifup enp189s0f3

pkgname=netperf
pkgver=2.7
pkgrel=0
source="https://github.com/HewlettPackard/netperf/archive/$pkgname-$pkgver.$pkgrel.tar.gz"

build() {
    ip route add default via 172.168.131.2
    yum install -y tar libpcap-devel gcc-c++ autoconf automake libtool make firewalld
    mkdir -p /netperf-source
    cd /netperf-source
    wget $source
    tar xvf $pkgname-$pkgver.$pkgrel.tar.gz
    cd $pkgname-$pkgname-$pkgver.$pkgrel

    ./autogen.sh

    ./config.guess > /dev/null 2>&1 || {
        curl -s -o config.guess 'http://git.savannah.gnu.org/gitweb/?p=config.git;a=blob_plain;f=config.guess;hb=HEAD'
        curl -s -o config.sub 'http://git.savannah.gnu.org/gitweb/?p=config.git;a=blob_plain;f=config.sub;hb=HEAD'
    }

    sed -i 's/(netperf_sendfile/(len = netperf_sendfile/g' src/nettest_bsd.c

    if [[ "$arch" == "aarch64" ]];then
        ./configure CFLAGS=-fcommon --host=arm-linux --build=arm-linux
    fi

    if [[ "$arch" == "x86_64" ]];then
        ./configure CFLAGS=-fcommon --host=x86-linux --build=x86-linux
    fi

    make -j
	
    export PATH="/netperf-source/$pkgname-$pkgname-$pkgver.$pkgrel/src/:$PATH"
}
build

. $LKP_SRC/lib/reproduce-log.sh

opt_ip=
[ "$ip" = 'ipv4' ] && opt_ip='-4'
[ "$ip" = 'ipv6' ] && opt_ip='-6'

# start netserver
systemctl stop firewalld

log_echo netserver $opt_ip 
exec netserver $opt_ip
